using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ReloadManager : MonoBehaviour
{
    public static ReloadManager instance;

    private void Awake()
    {
        if (instance != null)
        { 
            Destroy(instance);
        }
        instance = this;
    }

    public void ReloadGame()
    { 
        var needReloadOjbects = FindAllIReloadObjects();
        foreach(var obj in needReloadOjbects)
        {
            obj.Reload();
        }
    }

    public List<IReloadHandle> FindAllIReloadObjects()
    {
        IEnumerable<IReloadHandle> reloadHandles = FindObjectsOfType<MonoBehaviour>().OfType<IReloadHandle>();
        return new List<IReloadHandle>(reloadHandles);
    }
}
